<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<% pageContext.setAttribute("newLineChar","\n"); %>
<ul class="replyList">
	<c:forEach items="${commentList}" var="commentList">
	<li class="reply${ commentList.COMMT_DEPTH }">
		<div><strong><c:out value="${ commentList.COMMT_WRITER }" /> </strong><c:out value="${ commentList.COMMT_REGDATE }" />
			<span class="button btnProc03"><a href="#" id="commtDelete" onclick="replyDelete('deleteFrm','${ commentList.COMMT_ID }','${ commentList.JOB_ID }','${ commentList.RELATE_ID }','${ commentList.COMMT_WRITER }'); return false;">삭제</a></span>
			<%-- <c:if test="${ commentList.COMMT_DEPTH < 5 }">
			<span class="button btnProc04"><a href="#" onclick="reply('${ commentList.COMMT_ID }','${ commentList.JOB_ID }','${ commentList.RELATE_ID }','${ commentList.COMMT_REF }','${ commentList.COMMT_STEP }','${ commentList.COMMT_DEPTH }'); return false;">답글</a></span>
			</c:if> --%>
		</div>
		<div>${fn:replace(commentList.COMMT_CONTENTS,newLineChar,'<br />')}</div>
		<!-- [s]답글 클릭시 나오는 영역 -->
		<div class="hide" id="${ commentList.COMMT_ID }">
		</div>
	</li>
	</c:forEach>
</ul>
<div class="t20"><br/><br/></div>
<form name="writeFrm" action="" method="">
<div id="inputCommt">
	<table cellspacing="0" cellpadding="0" border="0" class="tbl_type04">
		<colgroup>
			<col width="150px" />
			<col width="200px" />
			<col width="150px" />
			<col />
		</colgroup>
		<tbody>
			<tr>
				<th>이름</th>
				<td>
					<input type="text" size="20" class="in" name="commt_writer" value="${ adminInfo.admin_name }" readonly />
					<input type="hidden" size="20" class="in" name="commt_writer_id" value="${ adminInfo.admin_id }" readonly />
					<input type="hidden" size="20" class="in" name="commt_step" value="0" readonly />
					<input type="hidden" size="20" class="in" name="commt_depth" value="0" readonly />
					<input type="hidden" size="20" class="in" name="returnURL" value="0" readonly />
				</td>
				<!-- <th>비밀번호</th> -->
				<td></td>
				<td><input type="hidden" size="20" class="in" name="commt_pw"/></td>
			</tr>
			<tr>
				<th>내용</th>
				<td colspan="3"><textarea rows="5" class="in2" style="width:99%" name="commt_contents"></textarea></td>
			</tr>
			
		</tbody>
	</table>
</div>
</form>	
<div class="ar t10">
	<span class="button btnProc01"><a href="#" id="commtBtn" onclick="commtFnc(); return false;">답변 등록</a></span>
</div>
<div>
<form name="deleteFrm" action="/common/commentReplyDelete.do" enctype="multipart/form-data" method="POST">
	<input type="hidden" name="commt_id" />
	<input type="hidden" name="job_id" />
	<input type="hidden" name="returnURL" />
</form>
</div>
<script type="text/javascript">
	//코멘트등록
	function commtFnc()
    {
	    	var frm = document.forms["writeFrm"];
	    	
	    	if (!isTextValidate(frm.commt_contents, "string", 0, "내용"))			return false;
	    	var bbs_id = frm.bbs_id.value;
	    	var article_id = frm.article_id.value;
	    	frm.returnURL.value="redirect:../bbs/"+bbs_id+"_view.do?article_id="+article_id;
	    	frm.action = "/common/commentInsert.do";
	    	frm.submit();
	
    }
	
	//코멘트 답글
	function reply(id,job_id,relate_id,commt_ref,step,depth)
	{
		
		var obj = document.getElementById(id);
		obj.className = "";
		var str = "<form name='replyFrm' action='/common/commentReplyInsert.do' enctype='multipart/form-data' method='POST'>";
		str += "<input type='hidden' name='job_id' value='"+job_id+"' />";
		str += "<input type='hidden' name='relate_id' value='"+relate_id+"' />";
		str += "<input type='hidden' name='commt_ref' value='"+commt_ref+"' />";
		str += "<input type='hidden' name='commt_step' value='"+step+"' />";
		str += "<input type='hidden' name='commt_depth' value='"+depth+"' />";
		str += "<input type='hidden' name='returnURL' value='"+"redirect:../bbs/"+job_id+"_view.do?article_id="+relate_id+"' />";
		str += document.getElementById("inputCommt").innerHTML;
		str += "<div class='ar t10'>";
		str += "<span class='button btnProc01'><a href='#' id='replyBtn' onclick='replyFnc();'>댓글 등록</a></span>";
		str += "</div>";
		str += "</form>";
		obj.innerHTML = str;

	}
	
	//코멘트등록
	function replyFnc()
    {
		var frm = document.forms["replyFrm"];
    	
    	if (!isTextValidate(frm.commt_pw, "string", 0, "비밀번호"))			return false;
    	if (!isTextValidate(frm.commt_contents, "string", 0, "내용"))			return false;
    	
    	frm.action = "/common/commentReplyInsert.do";
    	frm.submit();
    }
	
	//코멘트삭제
	function replyDelete(form, commt_id, job_id, relate_id, writer )
    {
		if('${adminInfo.admin_name}' == writer)
		{
			if (!confirm("정말로 삭제하시겠습니까?"))
	   		{
				return false;
	   		}  

			var frms = document.forms["writeFrm"];
	    	var bbs_id = frms.bbs_id.value;
	    	var article_id = frms.article_id.value;
		
			var frm = document.forms["deleteFrm"];
			frm.commt_id.value=commt_id;
			frm.job_id.value=job_id;
	    	frm.returnURL.value="redirect:../bbs/"+bbs_id+"_view.do?article_id="+article_id;
			frm.action = "/common/commentReplyDelete.do";
			frm.submit();
		}
		else
		{
			alert("다른 아이디의 글은 삭제 할 수 없습니다.");
			
			return false;
		}
    }
	</script>